package xyz.xmh.pattern.structural.flyweightpattern;

import java.util.Random;

/**
 * @author Administrator
 * 享元模式演示类
 * 作用是减少创建对象，重复利用已创建的对象
 */
public class FlyweightPatternDemo {

    private static final String[] COLORS = {"白色", "黑色", "蓝色", "黄色", "红色"};

    public static void main(String[] args) {

        Random random = new Random(47);

        // 圆形数量
        int circles = 20;

        for (int i = 0; i < circles; i++) {
            // 使用工厂方法创建圆形对象
            Circle circle = (Circle) ShapeFactory.getCircle(COLORS[random.nextInt(COLORS.length)]);

            // 填充属性
            circle.setX(random.nextInt());
            circle.setY(random.nextInt());
            circle.setRadius(random.nextInt());

            // 调用方法
            circle.draw();

        }

    }

}
